import Vue from 'vue'
import Vuex from 'vuex'
import api from '../api'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 搜索验证规则
    QueryRules: {
      Mechanism: [
        { required: true, message: '请选择机构', trigger: 'change' }
      ],
      Department: [
        { required: true, message: '请选择部门', trigger: 'change' }
      ],
      StopTime: [
        { required: true, message: '请填写止期', trigger: 'change' }
      ]
    },
    // 编辑验证规则
    EditRules: {
      score: [
        { required: true, message: '请填写评分', trigger: 'blur' }
      ]
    },
    // 机构
    orgdata: [],
    // 部门
    departdata: [],

  },
  mutations: {
    // 修改机构，修改部门
    changeOrg(state, data) {
      state.orgdata = data
    },
    changeDepart(state, data) {
      state.departdata = data
    },
    // 根据部门id获取部门名称
    getorgname(state,data) {
      const x=state.departdata.find(item => {
        return item.departId === data
      }).departName
      console.log(x);
      return x;
    }
  },
  actions: {
    GetOrg(store) {
      api.org.all().then(res => {
        if (res.data.success == true) {
          store.commit('changeOrg', res.data.data)
        }
      });
    },
    GetDepart(store) {
      api.depart.all().then(res => {
        if (res.data.success == true) {
          store.commit('changeDepart', res.data.data)
        }
      });
    }
  },
  modules: {
  }
})
